const webpack = require('webpack');
const path = require('path');
const TransferWebpackPlugin = require('transfer-webpack-plugin');

const config = {
    // Entry points to the project
    entry: {
        main: [
            // only- means to only hot reload for successful updates
            'webpack/hot/only-dev-server',
            './src/app/app.js',
        ],
    },
    // Server Configuration options
    devServer: {
        contentBase: 'src/www', // Relative directory for base of server
        hot: true, // Live-reload
        inline: true,
        port: 4000, // Port Number
        host: 'localhost', // Change to '0.0.0.0' for external facing server
    },
    devtool: 'cheap-source-map',//'eval',
    output: {
        path: path.resolve(__dirname, 'build'), // Path of output file
        filename: 'app.js',
    },
    plugins: [
        // videojs
        new webpack.ProvidePlugin({
            //'vjs': 'video.js/dist/video',
            //'vjs': ['video.js/dist/video', 'default'],
            //"videojs": "video.js/dist/video.min.js",
            //"window.videojs": "video.min.js",
            //'_': 'lodash/lodash',
            '_': 'lodash',
            '$': 'jquery',
        }),
        // Enables Hot Modules Replacement
        new webpack.HotModuleReplacementPlugin(),
        // Moves files
        new TransferWebpackPlugin([
            {from: 'www'},
        ], path.resolve(__dirname, 'src')),

    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    cacheDirectory: true,
                },
            },
            {
                test: /\.css$/,
                use: [
                    {loader: "style-loader"},
                    {loader: "css-loader"},
                ],
            },
            {
                loader: 'url-loader?limit=100000',
                test: /\.(png|woff|woff2|eot|ttf|svg)$/
            }
        ],
    },
    resolve: {
        alias: {
            'webworkify': 'webworkify-webpack-dropin'
            //'videojs-contrib-hls': __dirname + '/node_modules/videojs-contrib-hls/dist/videojs-contrib-hls',
            //webworkify$: 'webworkify-webpack'
        }
    }
};

module.exports = config;
